package proxirabais.mobile;

import proxirabais.mobile.activity.NewUserMarkerActivity;
import proxirabais.mobile.activity.ProxirabaisMobileActivity;
import proxirabais.mobile.activity.ShowMarkerActivity;
import proxirabais.mobile.item.MarkerOverlayItem;
import messages.SystemMessage;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

import com.google.android.maps.MapActivity;
import com.google.android.maps.OverlayItem;

public class MarkerAction {
	
	private ProxirabaisMobileActivity mContext;	
	MarkerAction (MapActivity context)
	{
		this.mContext = (ProxirabaisMobileActivity)context;
	}
	

	public void showMarker(MarkerOverlayItem item) {
		Bundle bundle = new Bundle();
		bundle.putString(SystemMessage.PROMOTION_ID, item.getRealID()+"");
		
		
		Intent myIntent = new Intent(mContext.getMapView().getContext(), ShowMarkerActivity.class);
		myIntent.putExtras(bundle);
		mContext.startActivityForResult(myIntent, 0);

	}

	
	public void addNewUserMarker(final OverlayItem item)
	{
		AlertDialog.Builder dialog = new AlertDialog.Builder(this);
		
		dialog.setTitle(R.string.titreUserMarker);
		dialog.setMessage(R.string.MessageDialogNewMarkerWarning);
		dialog.setCancelable(true);
		dialog.setPositiveButton(R.string.MessageDialogAjouterMarker, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				Bundle bundle = new Bundle();
				bundle.putString(SystemMessage.PROMOTION_LONGITUDE, item.getPoint().getLongitudeE6()+"");
				bundle.putString(SystemMessage.PROMOTION_LATITUDE, item.getPoint().getLatitudeE6()+"");
				
				Intent myIntent = new Intent(mapView.getContext(), NewUserMarkerActivity.class);
				myIntent.putExtras(bundle);
				startActivityForResult(myIntent, 0);
				
				dialog.cancel();
			}
		});

		dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {              

				dialog.cancel();
			}
		});
		dialog.show();		

	}
}
